<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Rails::Generators::Testing::Behaviour</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../css/github.css" type="text/css" media="screen" />
<script src="../../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Module</span> 
            Rails::Generators::Testing::Behaviour 
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../../files/railties/lib/rails/generators/testing/behaviour_rb.html">railties/lib/rails/generators/testing/behaviour.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  


  


  
  


  
    <!-- Namespace -->
    <div class="sectiontitle">Namespace</div>
    <ul>
      
        <li>
          <span class="type">MODULE</span>
          <a href="Behaviour/ClassMethods.html">Rails::Generators::Testing::Behaviour::ClassMethods</a>
        </li>
      
    </ul>
  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>C</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Behaviour.html#method-i-create_generated_attribute">create_generated_attribute</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>G</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Behaviour.html#method-i-generator">generator</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>R</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Behaviour.html#method-i-run_generator">run_generator</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-create_generated_attribute">
            
              <b>create_generated_attribute</b>(attribute_type, name = 'test', index = nil)
            
            <a href="Behaviour.html#method-i-create_generated_attribute" name="method-i-create_generated_attribute" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Create a Rails::Generators::GeneratedAttribute by supplying the attribute
type and, optionally, the attribute name:</p>

<pre>create_generated_attribute(:string, 'name')</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-create_generated_attribute_source')" id="l_method-i-create_generated_attribute_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/cfb37a899d915fbfc63b36e7b1627c5c63cfa622/railties/lib/rails/generators/testing/behaviour.rb#L79" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-create_generated_attribute_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/testing/behaviour.rb, line 79</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">create_generated_attribute</span>(<span class="ruby-identifier">attribute_type</span>, <span class="ruby-identifier">name</span> = <span class="ruby-string">'test'</span>, <span class="ruby-identifier">index</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-constant">Rails</span><span class="ruby-operator">::</span><span class="ruby-constant">Generators</span><span class="ruby-operator">::</span><span class="ruby-constant">GeneratedAttribute</span>.<span class="ruby-identifier">parse</span>([<span class="ruby-identifier">name</span>, <span class="ruby-identifier">attribute_type</span>, <span class="ruby-identifier">index</span>].<span class="ruby-identifier">compact</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">':'</span>))
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-generator">
            
              <b>generator</b>(args=self.default_arguments, options={}, config={})
            
            <a href="Behaviour.html#method-i-generator" name="method-i-generator" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Instantiate the generator.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-generator_source')" id="l_method-i-generator_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/cfb37a899d915fbfc63b36e7b1627c5c63cfa622/railties/lib/rails/generators/testing/behaviour.rb#L71" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-generator_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/testing/behaviour.rb, line 71</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">generator</span>(<span class="ruby-identifier">args</span>=<span class="ruby-keyword">self</span>.<span class="ruby-identifier">default_arguments</span>, <span class="ruby-identifier">options</span>={}, <span class="ruby-identifier">config</span>={})
  <span class="ruby-ivar">@generator</span> <span class="ruby-operator">||=</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">generator_class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">args</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">config</span>.<span class="ruby-identifier">reverse_merge</span>(<span class="ruby-identifier">destination_root</span><span class="ruby-operator">:</span> <span class="ruby-identifier">destination_root</span>))
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-run_generator">
            
              <b>run_generator</b>(args=self.default_arguments, config={})
            
            <a href="Behaviour.html#method-i-run_generator" name="method-i-run_generator" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Runs the generator configured for this class. The first argument is an
array like command line arguments:</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">AppGeneratorTest</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">Rails</span><span class="ruby-operator">::</span><span class="ruby-constant">Generators</span><span class="ruby-operator">::</span><span class="ruby-constant">TestCase</span>
  <span class="ruby-identifier">tests</span> <span class="ruby-constant">AppGenerator</span>
  <span class="ruby-identifier">destination</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-string">&quot;../tmp&quot;</span>, <span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-keyword">__FILE__</span>))
  <span class="ruby-identifier">teardown</span> :<span class="ruby-identifier">cleanup_destination_root</span>

  <span class="ruby-identifier">test</span> <span class="ruby-string">&quot;database.yml is not created when skipping Active Record&quot;</span> <span class="ruby-keyword">do</span>
    <span class="ruby-identifier">run_generator</span> <span class="ruby-node">%w(myapp --skip-active-record)</span>
    <span class="ruby-identifier">assert_no_file</span> <span class="ruby-string">&quot;config/database.yml&quot;</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
</pre>

<p>You can provide a configuration hash as second argument. This method
returns the output printed by the generator.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-run_generator_source')" id="l_method-i-run_generator_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/cfb37a899d915fbfc63b36e7b1627c5c63cfa622/railties/lib/rails/generators/testing/behaviour.rb#L63" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-run_generator_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/testing/behaviour.rb, line 63</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">run_generator</span>(<span class="ruby-identifier">args</span>=<span class="ruby-keyword">self</span>.<span class="ruby-identifier">default_arguments</span>, <span class="ruby-identifier">config</span>={})
  <span class="ruby-identifier">capture</span>(<span class="ruby-value">:stdout</span>) <span class="ruby-keyword">do</span>
    <span class="ruby-identifier">args</span> <span class="ruby-operator">+=</span> [<span class="ruby-string">'--skip-bundle'</span>] <span class="ruby-keyword">unless</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">include?</span> <span class="ruby-string">'--dev'</span>
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">generator_class</span>.<span class="ruby-identifier">start</span>(<span class="ruby-identifier">args</span>, <span class="ruby-identifier">config</span>.<span class="ruby-identifier">reverse_merge</span>(<span class="ruby-identifier">destination_root</span><span class="ruby-operator">:</span> <span class="ruby-identifier">destination_root</span>))
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    